import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.util.Map;
import java.util.logging.Logger;
import javax.swing.event.MouseInputListener;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Camera;
import org.rsbot.script.methods.Equipment;
import org.rsbot.script.methods.Inventory;
import org.rsbot.script.util.Timer;
import org.rsbot.script.util.WindowUtil;
import org.rsbot.script.wrappers.RSItem;

@ScriptManifest(authors={"vilon"}, name="Voluntary Thieve", keywords={"Thieving"}, version=1.13D, description="Blackjacks/pickpockets the trainers and volunteers in the Thieves' Guild.")
public final class VoluntaryThieve extends Script
  implements MouseInputListener, PaintListener, MessageListener
{
  private static final ScriptManifest scriptManifest = (ScriptManifest)VoluntaryThieve.class.getAnnotation(ScriptManifest.class);

  private final VoluntaryThieve.Actions actions = new VoluntaryThieve.Actions(this, null);

  private final VoluntaryThieve.Antibans antibans = new VoluntaryThieve.Antibans(this, null);

  private final VoluntaryThieve.Conditions conditions = new VoluntaryThieve.Conditions(this, null);

  private final VoluntaryThieve.Configuration configuration = new VoluntaryThieve.Configuration(this, null);
  private VoluntaryThieve.Options options;
  private VoluntaryThieve.Progress progress;
  private VoluntaryThieve.Action currentAction;
  private VoluntaryThieve.Action previousAction;
  private VoluntaryThieve.Action.State actionState;
  private boolean isStartupActionsDone;

  public void messageReceived(MessageEvent paramMessageEvent)
  {
    if (paramMessageEvent.getID() != 0) {
      return;
    }
    String str = paramMessageEvent.getMessage();
    if (str != null)
      if (str.contains("attempt to")) {
        VoluntaryThieve.Actions.access$4502(this.actions, true);
      } else if (str.contains("handkerchief")) {
        VoluntaryThieve.Progress.access$10608(this.progress);
      } else if (str.contains("smack")) {
        VoluntaryThieve.Progress.access$14908(this.progress);
      } else if ((str.contains("been stunned")) || (str.contains("glances"))) {
        if (VoluntaryThieve.Options.access$900(this.options)) {
          VoluntaryThieve.Progress.access$15008(this.progress);
          VoluntaryThieve.Actions.access$5502(this.actions, true);
        } else {
          VoluntaryThieve.Progress.access$15108(this.progress);
          if (VoluntaryThieve.Actions.access$1600(this.actions) == null)
            VoluntaryThieve.Actions.access$1602(this.actions, new Timer(random(4320, 4765)));
          else VoluntaryThieve.Actions.access$1600(this.actions).setEndIn(random(4320, 4765)); 
        }
      }
      else if (str.contains("worn out")) {
        VoluntaryThieve.Progress.access$15208(this.progress);
        VoluntaryThieve.Actions.access$4902(this.actions, false);
      } else if (str.contains("can't reach")) {
        VoluntaryThieve.Actions.access$15302(this.actions, true);
      }
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
    if ((this.progress != null) && (VoluntaryThieve.Actions.Methods.access$13600(VoluntaryThieve.Actions.access$1700(this.actions))))
      VoluntaryThieve.Progress.access$15400(this.progress, paramMouseEvent);
  }

  public void mouseMoved(MouseEvent paramMouseEvent) {
    if ((this.progress != null) && (VoluntaryThieve.Actions.Methods.access$13600(VoluntaryThieve.Actions.access$1700(this.actions))))
      VoluntaryThieve.Progress.access$15500(this.progress, paramMouseEvent);
  }

  public void onRepaint(Graphics paramGraphics) {
    if ((this.options != null) && (VoluntaryThieve.Actions.Methods.access$13600(VoluntaryThieve.Actions.access$1700(this.actions)))) {
      if (this.progress == null) this.progress = new VoluntaryThieve.Progress(this, null);
      VoluntaryThieve.Progress.access$15700(this.progress, paramGraphics);
    }
  }

  public boolean onStart()
  {
    if (VoluntaryThieve.Update.access$15900(new VoluntaryThieve.Update(this, null))) return false;

    VoluntaryThieve.GraphicalInterface localGraphicalInterface = new VoluntaryThieve.GraphicalInterface(this, null);
    WindowUtil.position(localGraphicalInterface);
    localGraphicalInterface.setVisible(true);

    while (localGraphicalInterface.isVisible()) sleep(1000);
    boolean bool = false;
    try
    {
      bool = VoluntaryThieve.GraphicalInterface.access$16100(localGraphicalInterface);
    } catch (IllegalStateException localIllegalStateException) {
    }
    if (!bool) return false;
    try
    {
      this.options = new VoluntaryThieve.Options(this, VoluntaryThieve.GraphicalInterface.access$16200(localGraphicalInterface), null);
    } catch (IllegalArgumentException localIllegalArgumentException) {
      this.log.warning(localIllegalArgumentException.getMessage());
      return false;
    }

    VoluntaryThieve.Options.access$16400(this.options);
    return true;
  }

  public void onFinish()
  {
    if (this.progress != null)
      VoluntaryThieve.Progress.access$16500(this.progress);
  }

  public int loop()
  {
    if (!VoluntaryThieve.Actions.Methods.access$13600(VoluntaryThieve.Actions.access$1700(this.actions))) {
      return random(50, 100);
    }

    if (!this.isStartupActionsDone) {
      VoluntaryThieve.Actions.access$1102(this.actions, VoluntaryThieve.Actions.Methods.access$16600(VoluntaryThieve.Actions.access$1700(this.actions)));
      this.log.fine(new StringBuilder().append("Location offset: ").append(VoluntaryThieve.Actions.access$1100(this.actions).x).append(", ").append(VoluntaryThieve.Actions.access$1100(this.actions).y).toString());

      this.camera.setAngle(random(0, 360));
      this.camera.setPitch(true);
      if (VoluntaryThieve.Options.access$900(this.options)) {
        if (this.inventory.contains(18644)) {
          this.inventory.getItem(new int[] { 18644 }).doAction("Wield");
        } else if (!this.equipment.containsAll(new int[] { 18644 })) {
          this.log.warning("Character must have a rubber blackjack equipped before starting.");
          return -1;
        }
      }

      this.isStartupActionsDone = true;
    }

    if (this.progress != null) {
      String str = VoluntaryThieve.Conditions.access$16700(this.conditions);
      if (str != null) {
        log(str);
        stopScript(true);
      }

    }

    if ((this.currentAction == null) && (this.actionState == null)) {
      this.currentAction = VoluntaryThieve.Actions.access$16800(this.actions);
    }

    if (this.currentAction == null) {
      this.log.severe(new StringBuilder().append("Script failed ").append(this.previousAction != null ? new StringBuilder().append("when ").append(VoluntaryThieve.Action.access$16900(this.previousAction).toLowerCase()).toString() : "unexpectedly").append(".").toString());

      stopScript(true);
    }

    this.actionState = VoluntaryThieve.Action.access$17000(this.currentAction);
    if (this.actionState != VoluntaryThieve.Action.State.PROGRESSING) {
      this.log.fine(new StringBuilder().append(VoluntaryThieve.Action.access$16900(this.currentAction)).append(" ").append(this.actionState.toString().toLowerCase()).append(".").toString());

      if ((VoluntaryThieve.Action.access$17100(this.currentAction) == 2) && (this.actionState == VoluntaryThieve.Action.State.COMPLETED))
      {
        VoluntaryThieve.Actions.access$1000(this.actions).clear();
      }

      if ((VoluntaryThieve.Action.access$17100(this.currentAction) == 14) && (this.actionState == VoluntaryThieve.Action.State.FAILED))
      {
        this.log.warning("The character is not inside the guild.");
        stopScript(true);
      }

      this.previousAction = this.currentAction;
      this.currentAction = VoluntaryThieve.Actions.access$16800(this.actions);

      if ((VoluntaryThieve.Action.access$17100(this.previousAction) == 11) && (this.currentAction != null) && (VoluntaryThieve.Action.access$17100(this.currentAction) != 11))
      {
        VoluntaryThieve.Progress.access$17208(this.progress);
      }
    }

    return random(20, 85);
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mouseDragged(MouseEvent paramMouseEvent)
  {
  }
}